package com.emergency.embackend.controller;


import com.emergency.embackend.common.R;
import com.emergency.embackend.entity.Quiz;
import com.emergency.embackend.param.QuizDataParam;
import com.emergency.embackend.param.QuizSubmitParam;
import com.emergency.embackend.param.QuizSuitParam;
import com.emergency.embackend.service.QuizDataService;
import com.emergency.embackend.vo.QuizSubmitVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("quiz/data")
public class QuizDataController {
    @Autowired
    private QuizDataService quizDataService;
    @PostMapping("/pageAll")
    public R pageAll(@RequestBody QuizSuitParam param){
        if(param == null){
            return R.error(500,"请联系管理员");
        }
        return R.ok().put("data",quizDataService.pageAll(param));
    }

    @PostMapping("getQuizDataBySuitId")
    public R getQuizDataBySuitId(@RequestParam("quizSuitId") Long quizSuitId){
        if(quizSuitId == null){
            return R.error(500,"请联系管理员");
        }
        return R.ok().put("data",quizDataService.getQuizDataBySuitId(quizSuitId));
    }

    @PostMapping("update")
    public R update(@RequestBody Quiz quiz){
        if(quiz == null){
            return R.error(500,"请联系管理员");
        }
        quizDataService.update(quiz);
        return R.ok();
    }
    @PostMapping("add")
    public R add(@RequestBody Quiz quiz){
        if(quiz == null){
            return R.error(500,"请联系管理员");
        }
        quizDataService.add(quiz);
        return R.ok();
    }
    @GetMapping("delete")
    public R delete(@RequestParam("id") Long id){
        if(id == null){
            return R.error(500,"请联系管理员");
        }
        quizDataService.delete(id);
        return R.ok();
    }
    @PostMapping("submit")
    public R submit(@RequestBody QuizSubmitParam param){
        if(ObjectUtils.isEmpty(param)){
            return R.error("参数错误！！");
        }
        QuizSubmitVO quizSubmitVO = quizDataService.submit(param);
        return R.ok().put("data",quizSubmitVO);
    }
}
